using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
namespace Framework
{
    public static partial class Utils
    {
        public class ByteArraySerialize
        {
            /*
            public static void Write(ByteArray data, string value, string type)
            {
                if (type == "bool")
                {
                    data.Write(Utility.Parse.ParseBool(value));
                    return;
                }
                if (type == "int")
                {
                    data.Write(Utility.Parse.ParseInt(value)); return;
                }
                if (type == "byte")
                {
                    data.Write(Utility.Parse.ParseByte(value)); return;
                }
                if (type == "float")
                {
                    data.Write(Utility.Parse.ParseFloat(value)); return;
                }
                if (type == "string")
                {
                    data.Write(value);
                    return;
                }
                if (type == "byte[]")
                {
                    var list = Utility.Parse.ParseByteArray(value);
                    short count = ((short)list.Length);
                    data.Write(count);
                    for (int i = 0; i < count; i++)
                    {
                        data.Write(list[i]);
                    }
                    return;
                }
                if (type == "int[]")
                {
                    var list = Utility.Parse.ParseIntArray(value);
                    short count = ((short)list.Length);
                    data.Write(count);
                    for (int i = 0; i < count; i++)
                    {
                        data.Write(list[i]);
                    }
                    return;
                }
                if (type == "float[]")
                {
                    var list = Utility.Parse.ParseFloatArray(value);
                    short count = ((short)list.Length);
                    data.Write(count);
                    for (int i = 0; i < count; i++)
                    {
                        data.Write(list[i]);
                    }
                    return;
                }
                if (type == "string[]")
                {
                    var list = Utility.Parse.ParseStringArray(value);
                    short count = ((short)list.Length);
                    data.Write(count);
                    for (int i = 0; i < count; i++)
                    {
                        data.Write(list[i]);
                    }
                    return;
                }
                var datatype = Utility.Assembly.GetType(type);
                if (datatype != null)
                {
                    if (datatype.IsEnum)
                    {
                        data.Write(Utility.Parse.ParseInt(value));
                    }
                    else if (datatype.IsClass)
                    {
                        var ins=Activator.CreateInstance(datatype);
                        if(ins!=null)
                        {
                            
                        }
                    }
                }
                else
                {
                    data.Write(value);
                }
            }
            */
            public static bool ReadBool(ByteArray value)
            {
                return value.ReadBool();
            }
            public static int ReadInt(ByteArray value)
            {
                return value.ReadInt();
            }
            public static byte ReadByte(ByteArray value)
            {
                return value.ReadByte();
            }
            public static float ReadFloat(ByteArray value)
            {
                return value.ReadFloat();
            }
            public static byte[] ReadByteArray(ByteArray value)
            {
                var count = value.ReadShort();
                var data = new byte[count];
                for (int i = 0; i < count; i++)
                {
                    data[i] = value.ReadByte();
                }
                return data;
            }
            public static bool[] ReadBoolArray(ByteArray value)
            {
                var count = value.ReadShort();
                var data = new bool[count];
                for (int i = 0; i < count; i++)
                {
                    data[i] = value.ReadBool();
                }
                return data;
            }
            public static int[] ReadIntArray(ByteArray value)
            {
                var count = value.ReadShort();
                var data = new int[count];
                for (int i = 0; i < count; i++)
                {
                    data[i] = value.ReadInt();
                }
                return data;
            }
            public static float[] ReadFloatArray(ByteArray value)
            {
                var count = value.ReadShort();
                var data = new float[count];
                for (int i = 0; i < count; i++)
                {
                    data[i] = value.ReadFloat();
                }
                return data;
            }
            public static string[] ReadStringArray(ByteArray value)
            {
                var count = value.ReadShort();
                var data = new string[count];
                for (int i = 0; i < count; i++)
                {
                    data[i] = value.ReadString();
                }
                return data;
            }
            public static T ReadEnum<T>(ByteArray value)
            {
                return (T)Enum.ToObject(typeof(T), ReadInt(value));
            }
        }
    }
}